home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 7 / FM Towns Free Software Collection 7.iso / t_os / bb / src / bb.c next >
Encoding:
C/C++ Source or Header  |  1993-11-30  |  10.3 KB  |  436 lines

  1. /*
  2.     Basie's Browser
  3.         text display from text file
  4.  
  5.                       1993.6.27 v1.0
  6.                       copyright Y.Ouchi
  7.  
  8. */
  9.  
  10. #include    <stdio.h>
  11. #include    <string.h>
  12. #include    <stdlib.h>
  13. #include    <ctype.h>
  14. #include    <register.h>
  15. #include    "egb.h"
  16. #include    "mos.h"
  17. #include    "snd.h"
  18. #include    "bb.h"
  19. #include    "color.h"
  20.  
  21.     /*        関数プロトタイプ宣言                        */
  22.         int        intreal(int, union REGS *, union REGS *, struct SREGS *);
  23. extern    int        textdsp(char *,int,char **,struct logcontent *,short *,int *);
  24. extern    void    linedsp(int, int, char *);
  25. extern    void    box(int, int, int, int, int, int);
  26. extern    int        logcheck ( char *, int, char **, struct logcontent *, short *);
  27. extern    int        titlemod(char *,int,char **,struct logcontent *,short *,int *);
  28. extern    void    mesout ( int );
  29. extern    char    *filesel ( void );
  30. extern    void    parmode(struct logcontent *, short *);
  31.         void    initial ( void );
  32.         void    initial_panel ( void );
  33.  
  34.         char    egbwork[EGBWorkSize];
  35.         char    moswork[MosWorkSize];
  36.         int        max_title;
  37.         int        max_text;
  38.         int        max_content;
  39.         int        max_textn;
  40.         int        max_textp;
  41.         int        dispmode;
  42. static    FILE    *logFp;
  43. static    char    logfile[128]={""};
  44. static    char    *normalmode={"normal"};
  45. static    char    *parentmode={"parent"};
  46.  
  47. void main( int ac, char **av )
  48. {
  49.     char    *file_read_mes={"now file reading"};
  50.     char    *ext_char={".bak"};
  51.     char    *logtext;
  52.     char    **disp_title;
  53.     short    *disptextn;
  54.     short    *disptextp;
  55.     short    *disptext;
  56.     int        i,textno;
  57.     int        contf,back;
  58.     int        ext_ptr;
  59.     int        nowtext;
  60.     char    bupfile[128];
  61.     size_t    logtextleng;
  62.     struct    logcontent    *intext;
  63.     static    int        parmodedone=0;
  64.  
  65.                         /* input log file name check */
  66.     if (ac>=2) {
  67.         strcpy ( logfile, av[1] ) ;
  68.     }
  69.  
  70.                 /* initial display mode (parent mode) set */
  71.     dispmode=PARENT_MODE;
  72.  
  73.                         /* initialize */
  74.     initial();
  75.  
  76.     EGB_writePage(egbwork,1);
  77.     box(390,464,440,478,MODE_BACK_COL,1);
  78.     EGB_color(egbwork, 0, MODE_COL);
  79.     linedsp(391,478,parentmode);
  80.     EGB_writePage(egbwork,0);
  81.     EGB_color(egbwork, 0, TEXT_COL);
  82.  
  83.     if (strlen(logfile)==0) strcpy (logfile,filesel());
  84.  
  85.     while (strlen(logfile)!=0){
  86.  
  87.                         /* log file read */
  88.                             /*  file name separater change */
  89.                             /*  backup file name make (original+.bak) */
  90.         EGB_writePage(egbwork,1);
  91.         box(268,0,639,16,TITLEBACK_COL,1);
  92.         EGB_color(egbwork, 0, TITLE_COL);
  93.         linedsp(268,15,logfile );
  94.         EGB_writePage(egbwork,0);
  95.         ext_ptr=0;
  96.         for (i=0;i<strlen(logfile);i++){
  97.             if (logfile[i]==0x2e) ext_ptr=i;
  98.             if (logfile[i]==0x5c) logfile[i]=0x2f;
  99.         }
  100.         if (ext_ptr==0){
  101.             strcpy(bupfile,logfile);
  102.             strcat(bupfile,ext_char);
  103.         }
  104.         else{
  105.             strncpy(bupfile,logfile,ext_ptr);
  106.             bupfile[ext_ptr]=0x00;
  107.             strcat(bupfile,ext_char);
  108.         }
  109.  
  110.                         /*  memory get and file read */
  111.                         /* memory get for log analize & title display */
  112.  
  113.         (int)logtextleng=_get_file_size(logfile);
  114.  
  115.         if ( (int)logtextleng < 0 ){
  116.             mesout ( FILE_ERROR );
  117.             MOS_end();
  118.             exit(0);
  119.         }
  120.  
  121.         if ( (logtext=malloc(logtextleng+20))==NULL){
  122.             mesout ( MEMORY_ERROR );
  123.             MOS_end();
  124.             exit(0);
  125.         }
  126.         if (logtextleng<60000) logtextleng=60000;
  127.         max_text=logtextleng/500;
  128.         max_content=logtextleng/500;
  129.         max_title=logtextleng/2000;
  130.         if ((intext=malloc(sizeof(int)+sizeof(struct textcontent *)))==NULL ){
  131.             mesout(MEMORY_ERROR);
  132.             MOS_end();
  133.             exit(0);
  134.         }
  135.         if ( (intext->text=malloc(sizeof(union content)*max_content))==NULL ){
  136.             mesout(MEMORY_ERROR);
  137.             MOS_end();
  138.             exit(0);
  139.         }
  140.         if ( (disptextn=malloc(sizeof(short)*max_text))==NULL ){
  141.             mesout(MEMORY_ERROR);
  142.             MOS_end();
  143.             exit(0);
  144.         }
  145.         if ( (disptextp=malloc(sizeof(short)*max_text))==NULL ){
  146.             mesout(MEMORY_ERROR);
  147.             MOS_end();
  148.             exit(0);
  149.         }
  150.         if ( (disp_title=malloc(sizeof(void *)*max_title))==NULL ){
  151.             mesout(MEMORY_ERROR);
  152.             MOS_end();
  153.             exit(0);
  154.         }
  155.         for (i=0;i<max_title;i++){
  156.             if ( (disp_title[i]=malloc(sizeof(char)*90))==NULL ){
  157.                 mesout(MEMORY_ERROR);
  158.                 MOS_end();
  159.                 exit(0);
  160.             }
  161.         }
  162.  
  163.         logFp=fopen( logfile, "rb" );
  164.         if ( logFp == NULL ) {
  165.             mesout ( FILE_ERROR );
  166.             MOS_end();
  167.             exit(0);
  168.         }
  169.  
  170.         MOS_sysIcon(82,16,16,0);
  171.         MOS_color( 0,12 );
  172.         MOS_setpos(320,200);
  173.         MOS_disp(1);
  174.         EGB_writePage(egbwork,0);
  175.         EGB_color(egbwork, 0, TEXT_COL);
  176.         linedsp(256,290,file_read_mes);
  177.  
  178.         logtextleng=fread(logtext,1,logtextleng,logFp);
  179.         fclose ( logFp );
  180.         for (i=0;i<15;i++) logtext[logtextleng+i]=0x00;
  181.  
  182.         MOS_sysIcon(170,0,0,0);
  183.         MOS_disp(0);
  184.         MOS_color( 0,ARROW_COL );
  185.         EGB_color(egbwork, 0, BACK_COL);
  186.         EGB_clearScreen(egbwork);
  187.         EGB_color(egbwork, 0, TEXT_COL);
  188.  
  189.         EGB_writePage(egbwork,0);
  190.  
  191.         if (logcheck(logtext,logtextleng,disp_title,intext,disptextn) != 0){
  192.             if (dispmode==NORMAL_MODE){
  193.                 disptext=disptextn;
  194.                 max_text=max_textn;
  195.             }
  196.             else{
  197.                 parmode(intext,disptextp);
  198.                 parmodedone=1;
  199.                 for (i=0;i<max_textp;i++)
  200.                     if(intext->text[disptextp[i]].text.id!=TITLE_ID) break;
  201.                 if (i==0) i=1;
  202.                 disptext=&disptextp[i-1];
  203.                 max_text=max_textp-(i-1);
  204.             }
  205.             textno=0;
  206.             contf=1;
  207.             back=0;
  208.  
  209.             while ( contf ){
  210.  
  211.                     /* text display                     */
  212.  
  213.                 switch(textdsp(logtext,(int)logtextleng,disp_title,intext,
  214.                                                 disptext,&textno)){
  215.                     case 0 :        /* all quit */
  216.                         contf=0;
  217.                         free(logtext);
  218.                         for (i=0;i<max_title;i++) free(disp_title[i]);
  219.                         free(disp_title);
  220.                         free(intext->text);
  221.                         free(intext);
  222.                         free(disptextn);
  223.                         free(disptextp);
  224.                         parmodedone=0;
  225.                         logfile[0]=0x00;
  226.                         break;
  227.                     case 1 :        /* log save & quit */
  228.                         rename(logfile,bupfile);
  229.                         logFp=fopen( logfile, "wb" );
  230.                         if ( logFp == NULL ) {
  231.                             mesout(FILE_ERROR);
  232.                             MOS_end();
  233.                             exit(0);
  234.                         }
  235.                         clearerr(logFp);
  236.                         nowtext=disptext[textno];
  237.                         if(intext->text[nowtext-1].text.id==TITLE_ID){
  238.                             nowtext--;
  239.                         }
  240.                         fwrite((void *)&logtext[intext->text[nowtext].text.pos]
  241.                             ,1,logtextleng-(intext->text[nowtext].text.pos),
  242.                             logFp);
  243.                         if (ferror(logFp)!=0) mesout(FILE_ERROR);
  244.                         fclose(logFp);
  245.                         contf=0;
  246.                         for (i=0;i<max_title;i++) free(disp_title[i]);
  247.                         free(disp_title);
  248.                         free(intext->text);
  249.                         free(intext);
  250.                         free(logtext);
  251.                         free(disptextn);
  252.                         free(disptextp);
  253.                         parmodedone=0;
  254.                         logfile[0]=0x00;
  255.                         strcpy (logfile,filesel());
  256.                         break;
  257.                     case 2 :        /* title mode */
  258.                         EGB_clearScreen(egbwork);
  259.                         titlemod(logtext,(int)logtextleng,
  260.                                         disp_title,intext,disptext,&textno);
  261.                         back=0;
  262.                         break;
  263.                     case 3 :        /* new file select */
  264.                         EGB_clearScreen(egbwork);
  265.                         free(logtext);
  266.                         for (i=0;i<max_title;i++) free(disp_title[i]);
  267.                         free(disp_title);
  268.                         free(intext->text);
  269.                         free(intext);
  270.                         free(disptextn);
  271.                         free(disptextp);
  272.                         parmodedone=0;
  273.                         logfile[0]=0x00;
  274.                         strcpy (logfile,filesel());
  275.                         contf=0;
  276.                         break;
  277.                     case 4 :        /* mode change */
  278.                         nowtext=disptext[textno];
  279.                         EGB_clearScreen(egbwork);
  280.                         EGB_writePage(egbwork,1);
  281.                         box(390,464,440,478,MODE_BACK_COL,1);
  282.                         EGB_color(egbwork, 0, MODE_COL);
  283.                         if (dispmode==NORMAL_MODE){
  284.                             if(parmodedone==0){
  285.                                 parmode(intext,disptextp);
  286.                                 parmodedone=1;
  287.                             }
  288.                             for (i=0;i<max_textp;i++)
  289.                               if(intext->text[disptextp[i]].text.id!=TITLE_ID)
  290.                                             break;
  291.                             if (i==0) i=1;
  292.                             disptext=&disptextp[i-1];
  293.                             max_text=max_textp-(i-1);
  294.                             dispmode=PARENT_MODE;
  295.                             linedsp(391,478,parentmode);
  296.                         }
  297.                         else{
  298.                             dispmode=NORMAL_MODE;
  299.                             disptext=disptextn;
  300.                             max_text=max_textn;
  301.                             linedsp(391,478,normalmode);
  302.                         }
  303.                         EGB_writePage(egbwork,0);
  304.                         EGB_color(egbwork, 0, TEXT_COL);
  305.                         for (textno=max_text-1;textno>0;textno--)
  306.                                 if (nowtext==disptext[textno]) break;
  307.                         back=0;
  308.                         break;
  309.                     case 5 :        /* console */
  310.                         system("f:");
  311.                         system("cd \rbin");
  312.                         system("aricon");
  313.                         initial_panel ( );
  314.                         back=0;
  315.                         break;
  316.                 }
  317.             }
  318.         }
  319.         else{
  320.             mesout( LOG_ERROR );
  321.             EGB_clearScreen(egbwork);
  322.             free(logtext);
  323.             for (i=0;i<max_title;i++) free(disp_title[i]);
  324.             free(disp_title);
  325.             free(intext->text);
  326.             free(intext);
  327.             free(disptextn);
  328.             free(disptextp);
  329.             parmodedone=0;
  330.             logfile[0]=0x00;
  331.             strcpy (logfile,filesel());
  332.         }
  333.     }
  334.     MOS_end();
  335.     exit(0);
  336. }
  337.  
  338. /*
  339.     initial set
  340. */
  341.  
  342. void    initial(void)
  343. {
  344.         char    para[50];
  345. union    REGS    in;
  346. struct    SREGS    seg;
  347.         int        i;
  348.  
  349.                             /* initialization            */
  350.  
  351.                             /* key board initialize */
  352.  
  353.     in.h.ah = 0x05;
  354.     in.h.al = 0x01;
  355.     intreal(0x90, &in, &in, &seg);
  356.  
  357.     EGB_init(egbwork,EGBWorkSize);
  358.     EGB_resolution(egbwork,0,3);
  359.     EGB_resolution(egbwork,1,3);
  360.     EGB_displayPage(egbwork,1,3);
  361.  
  362.                             /* screen initialize        */
  363.     EGB_textZoom(egbwork,0,8,16);
  364.     EGB_textZoom(egbwork,1,16,16);
  365.  
  366.     EGB_writePage(egbwork,0);
  367.  
  368.     DWORD(para + 0) = palno;
  369.     for (i=0;i<palno;i++){
  370.         DWORD(para + 8*i+4) = colpal[i][0];
  371.         BYTE(para + 8*i+ 8) = colpal[i][3];
  372.         BYTE(para + 8*i+ 9) = colpal[i][1];
  373.         BYTE(para + 8*i+10) = colpal[i][2];
  374.         BYTE(para + 8*i+11) = 0;
  375.         EGB_palette(egbwork,1,para);
  376.     }
  377.     EGB_color(egbwork, 1, BACK_COL);
  378.     EGB_clearScreen(egbwork);
  379.  
  380.     EGB_writePage(egbwork,1);
  381.  
  382.     DWORD(para + 0) = palno;
  383.     for (i=0;i<palno;i++){
  384.         DWORD(para + 8*i+4) = colpal[i][0];
  385.         BYTE(para + 8*i+ 8) = colpal[i][3];
  386.         BYTE(para + 8*i+ 9) = colpal[i][1];
  387.         BYTE(para + 8*i+10) = colpal[i][2];
  388.         BYTE(para + 8*i+11) = 0;
  389.         EGB_palette(egbwork,1,para);
  390.     }
  391.     EGB_color(egbwork, 1, 0);
  392.     EGB_clearScreen(egbwork);
  393.  
  394.     EGB_displayPage(egbwork,1,3);
  395.  
  396.     MOS_start(moswork,MosWorkSize);
  397.     MOS_resolution( 0,3 );
  398.     MOS_writePage( 1 );
  399.     MOS_color( 0,ARROW_COL );
  400.  
  401.     SND_elevol_all_mute( 0xff );
  402.     SND_elevol_set( 1, 127, 127 );
  403.  
  404.     initial_panel( );
  405.  
  406.     return;
  407. }
  408.  
  409. /*
  410.     initial display panel set
  411. */
  412.  
  413. void    initial_panel(void)
  414. {
  415.     char    *headtitle={"                   file name ="};
  416.     char    *name={"B-Browser  V1.1"};
  417.  
  418.     EGB_writePage(egbwork,1);
  419.     EGB_color(egbwork, 1, 0);
  420.     EGB_clearScreen(egbwork);
  421.     box(0,0,639,34,TITLEBACK_COL,1);
  422.     box(0,462,639,479,TITLEBACK_COL,1);
  423.     EGB_color(egbwork, 0, TITLE_COL);
  424.     linedsp(20,15,headtitle );
  425.     EGB_color(egbwork, 0, NAME_COL);
  426.     EGB_fontStyle(egbwork, 1);
  427.     linedsp(20,15,name );
  428.     EGB_fontStyle(egbwork, 0);
  429.     EGB_color(egbwork, 0, TEXT_COL);
  430.     EGB_color(egbwork, 1, BACK_COL);
  431.     EGB_writePage(egbwork,0);
  432.     EGB_clearScreen(egbwork);
  433.     return;
  434. }
  435.  
  436.